package net.jalbum.filters;

import java.awt.event.ActionEvent;

import javax.swing.JLabel;
import javax.swing.SwingConstants;

import net.jalbum.filters.components.ExtendedSlider;
import se.datadosen.jalbum.Msg;

public class SepiaControl extends FilterControl {

	/**
	 *
	 */
	private static final long serialVersionUID = -7969686269619548580L;
	protected SepiaFilterPlugin sepiaFilterPlugin;
	protected ExtendedSlider strengthSlider;
	protected JLabel textStrength;

	public SepiaControl() {
	}

	public SepiaControl(final SepiaFilterPlugin sepiaFilterPlugin) {

		this.init(sepiaFilterPlugin);

		this.addSepiaControls();
	}

	protected void addSepiaControls() {
		this.textStrength = new JLabel(Msg.getString(this, "filters.sepia.strength"));
		this.strengthSlider = new ExtendedSlider(SwingConstants.HORIZONTAL, 0, 100, 100);
		this.strengthSlider.getSlider().setMinorTickSpacing(5);
		this.strengthSlider.getSlider().setPaintLabels(false);
		this.strengthSlider.setSliderWidth(FilterControl.SLIDER_WIDTH);
		this.strengthSlider.removeResetButton();

		this.strengthSlider.addActionListener(this);

		this.add(this.textStrength);
		this.add("br", this.strengthSlider);
	}

	protected void init(final SepiaFilterPlugin sepiaFilterPlugin) {
		this.sepiaFilterPlugin = sepiaFilterPlugin;

		super.init(sepiaFilterPlugin);
	}

	@Override
	public void actionPerformed(final ActionEvent e) {
		super.actionPerformed(e);

		if (e.getSource() == this.strengthSlider) {
			this.sepiaFilterPlugin.setStrength(this.strengthSlider.getValue());
			this.sepiaFilterPlugin.renderImage();
		}
	}

	public SepiaFilterPlugin getSepiaPanel() {
		return this.sepiaFilterPlugin;
	}

	public void setSepiaPanel(final SepiaFilterPlugin sepiaFilterPlugin) {
		this.sepiaFilterPlugin = sepiaFilterPlugin;
	}

	public ExtendedSlider getStrengthSlider() {
		return this.strengthSlider;
	}

	public void setStrengthSlider(final ExtendedSlider strengthSlider) {
		this.strengthSlider = strengthSlider;
	}

	public JLabel getTextStrength() {
		return this.textStrength;
	}

	public void setTextStrength(final JLabel textStrength) {
		this.textStrength = textStrength;
	}
}
